<?php
/**
 * 头文件，连接数据库
 * 传参：所要连接的连接名，用户名，密码，数据库名
 * User: 一日の恨
 * Date: 2016/10/29 0029
 * Time: 10:09
 */
class conn
{
    private $servername = "123.207.114.241:3306";
    private $username = "root";
    private $password = "root";
    private $dbname = "db_nenufish";

    /**
     * conn constructor.
     * 构造函数
     * @param $servername 数据库连接
     * @param $username 用户名
     * @param $password 密码
     * @param $dbname 数据库名
     */
    function __construct($servername, $username, $password, $dbname)
    {
        $this->servername = $servername;
        $this->username = $username;
        $this->password = $password;
        $this->dbname = $dbname;
    }

    /**
     *连接数据库
     */
    function connection()
    {
        $servername = $this->servername;
        $username = $this->username;
        $password = $this->password;
        $dbname = $this->dbname;

        $conn =mysqli_connect($servername,$username,$password,$dbname);
 
        
        if(!$conn)
        {
            exit('链接数据库失败!');
        }
        if(!mysqli_select_db($conn,$dbname))
        {
            exit(mysqli_errno().":".mysqli_error());
        }
        return $conn;
    }
}